clear; clc;


%% Score the peak data for all subjects and conditions
disp('SCORING');
% cfg = [];
allClusters = [];
Subjects;
for s = fieldnames(subject)'
    disp(['Subject: ' subject.(cell2mat(s)).Name]);
%     output = scoreTfcPeaks(subject.(cell2mat(s)));
    output = plotTfcPeaks(subject.(cell2mat(s)));
end
clearvars -except allClusters clusters



% 
% %% Cluster the peak data for all subjects and conditions
% disp('CLUSTERING')
% cfg = clusterTfcPeaks_DefaultCfg();
% allClusters = [];
% Subjects;
% for s = fieldnames(subject)'
%     disp(['Subject: ' subject.(cell2mat(s)).Name]);
%     output = clusterTfcPeaks(subject.(cell2mat(s)), cfg);
%     clusters.(cell2mat(s)) = output.clusters;
%     allClusters = [allClusters output.clusters];
% end
% clearvars -except allClusters clusters
% save('clusters', 'allClusters', '-v7.3');

% minn=NaN(1,length(clusters));maxx=NaN(1,length(clusters));
% for i=1:length(allClusters)
%     minn(i) = min([allClusters(i).members.time]);
%     maxx(i) = max([allClusters(i).members.time]);
% end
% diff = abs(maxx-minn);
% [D,I] = max(diff);
% disp(['Max diff within clusters: ' num2str(D) ' in cluster ' num2str(I)]);


% %% Plot all..
% % Normal, regionset 1
% cfg = plotClusteredTfcPeaks_DefaultCfg;
% cfg.EpochSetSelection = {};
% cfg.FrequencyBinSelection = {};
% cfg.DrawStddevs = true;
% cfg.DrawRegression = false;
% cfg.SubplotByRegion = 1; 
% cfg.SaveFigure = true;
% plotClusteredTfcPeaks(allClusters, cfg);
% % Normal, regionset 2
% cfg = plotClusteredTfcPeaks_DefaultCfg;
% cfg.EpochSetSelection = {};
% cfg.FrequencyBinSelection = {};
% cfg.DrawStddevs = true;
% cfg.DrawRegression = false;
% cfg.SubplotByRegion = 2; 
% cfg.SaveFigure = true;
% plotClusteredTfcPeaks(allClusters, cfg);

% %% Send an email
% setpref('Internet','SMTP_Server','smtp.uu.nl');
% setpref('Internet','E_mail','r.j.m.hendriks@uu.nl');
% sendmail({'ralph@affy.nl','r.j.m.hendriks@uu.nl','marijeterwal@gmail.com'},'Matlab notification','Work done..');